package jianzhi_offer;

public class _54_链表中环的入口结点 {
    public ListNode EntryNodeOfLoop(ListNode pHead)
    {
        if(pHead == null || pHead.next == null) return null;
        ListNode fast = pHead;
        ListNode slow = fast;
        while(fast != null && fast.next != null){
            slow = slow.next;
            fast = fast.next.next;
            if(fast == slow) break;
        }
        if(fast == null) return null;
        slow = pHead;
        //记得是慢指针退到开始 然后都走一步
        while(fast != slow){
            slow = slow.next;
            fast = fast.next;
        }
        return fast;
    }
}
